package ink.openmind.threadexception;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author wangzhuangzhuang
 * @Description: 使用线程池处理任务的时候，任务代码可能抛出RuntimeException，抛出异常后，线程池可能会进行捕获
 * 也可能创建一个新的线程来代替异常线程，但可能无法感知任务出现异常，需要考虑线程池异常情况
 * @date 2022-05-18 11:17
 */
public class ThreadExceptionDemoWithNoPrintException {
	public static void main(String[] args) {
		ExecutorService threadPool = Executors.newFixedThreadPool(5);
		for(int i = 0; i < 5; i ++){
			threadPool.submit(() -> {
				System.out.println("current thread name" + Thread.currentThread().getName());
				Object object = null;
				System.out.println("result##" + object.toString());
			});
		}
	}
}

// 这段代码会有异常，我们再来看看执行结果 未报异常
//		current thread namepool-1-thread-1
//		current thread namepool-1-thread-5
//		current thread namepool-1-thread-2
//		current thread namepool-1-thread-4
//		current thread namepool-1-thread-3